package com.zhiyou100.video.webaction.homepage;

import java.util.List;
import java.util.Set;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.zhiyou100.video.model.Course;
import com.zhiyou100.video.model.Speaker;
import com.zhiyou100.video.model.Subject;
import com.zhiyou100.video.model.Video;
import com.zhiyou100.video.service.CourseService;
import com.zhiyou100.video.service.VideoService;

@SuppressWarnings("all")
@Controller("HomePage")
@Scope(scopeName="prototype")
public class HomePage extends ActionSupport {
	private Integer subid;
	private Integer videoId;
	private Integer subjectId;
	
	
	public Integer getVideoId() {
		return videoId;
	}
	public void setVideoId(Integer videoId) {
		this.videoId = videoId;
	}
	public Integer getSubjectId() {
		return subjectId;
	}
	public void setSubjectId(Integer subjectId) {
		this.subjectId = subjectId;
	}
	public Integer getSubid() {
		return subid;
	}
	public void setSubid(Integer subid) {
		this.subid = subid;
	}
	@Autowired
	CourseService cs;
	public String index() throws Exception {
	Subject subject = new Subject();
	
	subject.setId(subid);
	DetachedCriteria dc = DetachedCriteria.forClass(Course.class);
	dc.add(Restrictions.eq("subjectId", subject));
	List<Course> list = cs.selectIndexVideo(dc);
	for (Course kk : list) {
		subject = kk.getSubjectId();
	}
		ActionContext.getContext().put("courses", list);
		ActionContext.getContext().put("subject", subject);
		
		return SUCCESS;
	}
	@Autowired
	VideoService vs;
	public String videoData() throws Exception {
		Speaker spe = new Speaker();
		Subject subject = new Subject();
		Video  vde = new Video();
		Course cou = new Course();
		subject.setId(subjectId);
		DetachedCriteria dc = DetachedCriteria.forClass(Video.class);
		dc.add(Restrictions.eq("id", videoId));
		List<Video> list = vs.selectVideok(dc);
		
		for (Video video : list) {
			 spe = video.getSid();
			 vde =video;
			 cou = video.getCid();
		}
		Course li = cs.selectCourseId(cou.getId());
		ActionContext.getContext().put("course", cou);
		ActionContext.getContext().put("video", vde);
		ActionContext.getContext().put("speaker", spe);
		ActionContext.getContext().put("videoList", li.getVideoSet());
		return "content";
	}
	public String videoindex() throws Exception {
		DetachedCriteria dc = DetachedCriteria.forClass(Subject.class);
		dc.add(Restrictions.idEq(subjectId));
		List<Subject> list = cs.selectvideoindex(dc);
//		Subject subject = new Subject();
//		for (Subject subjt : list) {
//			subject=subjt;
//		}
//		System.out.println(subject);
		ActionContext.getContext().put("subject", list.get(0));
		return "videoindex";
		
	}
	public void viceostate() throws Exception {
		cs.addViceoState(videoId);
		
	}

}
